package net.cl.mvc.wrappers;

import javax.servlet.ServletContext;


public class ActionContext {

	private RequestContext request;
	private ResponseContext response;
	private static final ThreadLocal<ActionContext> actionContext = new ThreadLocal<ActionContext>();
	private static ServletContext servletContext;

	private ActionContext() {
	}

	public static ActionContext getContext() {
		if (actionContext.get() == null)
			actionContext.set(new ActionContext());
		return actionContext.get();
	}

	public static void setContext(ActionContext context) {
		actionContext.set(context);
	}

	public RequestContext getRequestContext() {
		return request;
	}

	public ResponseContext getResponseContext() {
		return response;
	}

	public void setRequestContext(RequestContext request) {
		this.request = request;
	}

	public void setResponseContext(ResponseContext response) {
		this.response = response;
	}

	public static void setServletContext(ServletContext servletContext) {
		ActionContext.servletContext = servletContext;
	}

	public static ServletContext getServletContext() {
		return servletContext;
	}

	public static String getRealPath(String path) {
		return getServletContext().getRealPath(path);
	}

	public static String getContextPath() {
		return getServletContext().getContextPath();
	}

}
